Prompts and Prompt Engineering

Learn about prompts and their elements in prompt engineering.

What is a prompt?#

A prompt is a stimulus or cue to elicit a particular response or action. Prompts can take many forms, such as verbal or written instructions, visual cues, or physical gestures. For example, a teacher might give students a prompt to guide their writing on a specific topic.

svg viewer

In natural language processing and LLMs, a prompt is an input provided to the model in order to generate a response or prediction. The prompt can be a sentence, a question, a paragraph, or an instruction.

For example, when using a large language model to generate text, a prompt can be a few words or a sentence that provides a starting point for the model to generate a longer piece of text. Based on the prompt, the model then uses its language modeling capabilities to predict and generate the most likely continuation of the text. Similarly, in question-answering tasks, a prompt can be a question. The model uses it to generate a response based on its understanding of the context and knowledge in its training data.

The following are a few examples of prompts used for LLMs:

  • “What is the capital city of the United States of America?”

  • “List down the top five most played sports.”

  • “Explain the difference between ‘affect’ and ‘effect.’”

Prompt elements#

A prompt is made up of elements that make it effective and efficient. These elements can vary depending on the context and the purpose for which it is being used. A prompt can generally consist of one or more of the following elements.

Instruction#

An instruction is a set of tasks or guidelines that direct the response or action required from the model. This can include prompts that require specific information or a certain type of response. An instruction can be in the form of a question or a statement.

svg viewer

The clarity of the instruction is crucial, as it impacts the accuracy and relevance of the response generated by the model. Clear and concise prompts can reduce the likelihood of ambiguity or confusion in the generated output.

Here's an example of an instruction:

Prompt

Briefly describe the process of photosynthesis.

Context#

The context in a prompt refers to the background information or situation in which the prompt is being presented. It can include information such as the intended audience, the purpose of the task, and any relevant details that provide additional information about the task at hand.

svg viewer

By including the context in a prompt, the model can better understand the intended meaning of the prompt and generate more accurate and relevant responses. Context can also help ensure the AI model is tailored to the specific task or domain, improving its overall performance.

Prompt

Generate a product description for vegan protein bars targeted toward fitness enthusiasts. These new protein bars come in five different flavors.

In this example, the goal of the prompt is to generate a product description for protein bars. However, the prompt gives additional information about the product, like the type, variants, and target audience as context. This allows the model to generate an accurate and relevant response.

Constraints#

Constraints are limitations or requirements included in a prompt to guide the output generated by the model. Constraints can help to ensure that the generated content meets criteria or conforms to certain rules. They can also be used to encourage creativity or to introduce additional challenges or limitations.

svg viewer

Constraints can be helpful in various applications, such as generating product descriptions, summarizing articles, or creating artwork. By providing clear guidelines for the output generated by the model, constraints can help ensure that the generated content is relevant, accurate, and meets the intended audience's needs.

Prompt

Write a 500-word short story about a detective solving a murder mystery. The story should include at least three clues that the detective uses to solve the mystery. The tone should be suspenseful, with a focus on building tension and keeping the reader engaged. The story should feature at least three characters. Finally, the story must include the phrase "the plot thickens" somewhere in the middle.

In this prompt, the constraints include the word count, genre, tone, and theme of the story. Additionally, there are elements that must be included (such as the clues and the characters), and the requirement to use a specific phrase. These constraints help ensure that the generated short story meets the reader's expectations and creates a compelling narrative.

Format#

The format refers to the structure or layout of the generated text that the prompt is intended to produce. Defining the desired output format in the prompt makes it easier to generate text that meets the user’s expectations and fits within the desired context. The output format can also help ensure consistency and coherence in the generated text.

svg viewer

Prompt

<Text>

From the above text, identify and list names and places in this format:

Names: name 1, name 2

Places: place 1, place 2

This prompt specifies a format in which the output should be generated. The names and places are separately listed using commas. The output format makes it easy to understand and use the generated response.

Prompt engineering#

Prompt engineering is the process of designing effective prompts for generative AI models. Prompt engineering aims to provide clear and specific instructions to the AI model on what type of output is desired. This helps ensure the generated content is accurate, relevant and meets the user’s needs.

A prompt could include context about a specific topic or task, constraints about the tone or style of the output, and a format for how the output should be structured. The AI model can generate content that meets the user’s needs and requirements by including these elements in the prompt.

svg viewer

It is important to note that the choice of prompt elements depends on the task or goal. Some tasks may require more specific and detailed prompts, while others only need a few essential elements. The important thing is to include the necessary information in the prompt to guide the model toward producing the desired output.

Generative AI

Types of Prompts